package o;

import android.content.Context;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
import java.util.LinkedList;
import java.util.Queue;
import o.bkw.b;
import o.bkw.d;

public class ezn {
    private static ezn ॱ = null;
    protected Context ˊ = ContentManager.getInstant().getContext();
    private Handler ˋ = new Handler(this) {
        final /* synthetic */ ezn ˊ;

        {
            this.ˊ = r1;
        }

        public void handleMessage(Message message) {
            a aVar;
            if (message.what == 1) {
                if (!this.ˊ.ˎ) {
                    aVar = (a) this.ˊ.ˏ.poll();
                    if (aVar != null) {
                        this.ˊ.ˎ = true;
                        try {
                            ((WindowManager) this.ˊ.ˊ.getSystemService("window")).addView(aVar.ॱ(), aVar.ˋ());
                        } catch (Throwable e) {
                            Logger.ˋ("BuoyToast", "addView exception", e);
                        }
                        Message message2 = new Message();
                        message2.what = 3;
                        message2.obj = aVar;
                        this.ˊ.ˋ.sendMessageDelayed(message2, aVar.ˎ());
                    }
                }
            } else if (message.what == 3) {
                aVar = (a) message.obj;
                if (aVar != null) {
                    try {
                        ((WindowManager) this.ˊ.ˊ.getSystemService("window")).removeViewImmediate(aVar.ॱ());
                    } catch (Throwable e2) {
                        Logger.ˋ("BuoyToast", "removeViewImmediate exception", e2);
                    }
                }
                this.ˊ.ˎ = false;
                this.ˊ.ˋ.sendEmptyMessage(1);
            } else {
                this.ˊ.ˎ = false;
            }
        }
    };
    private boolean ˎ = false;
    private Queue<a> ˏ = new LinkedList();

    public static class a {
        private LayoutParams ˊ;
        private View ˋ;
        private long ॱ;

        public View ॱ() {
            return this.ˋ;
        }

        public void ॱ(View view) {
            this.ˋ = view;
        }

        public LayoutParams ˋ() {
            return this.ˊ;
        }

        public void ˎ(LayoutParams layoutParams) {
            this.ˊ = layoutParams;
        }

        public long ˎ() {
            return this.ॱ;
        }

        public void ˊ(long j) {
            this.ॱ = j;
        }

        public String toString() {
            return "ToastBean{" + "toastView=" + this.ˋ + ", params=" + this.ˊ + ", time=" + this.ॱ + '}';
        }
    }

    protected ezn() {
    }

    public static synchronized ezn ˊ() {
        ezn o_ezn;
        synchronized (ezn.class) {
            if (ॱ == null) {
                ॱ = new ezn();
            }
            o_ezn = ॱ;
        }
        return o_ezn;
    }

    public void ˊ(String str) {
        ॱ(str, 0);
    }

    public void ॱ(String str, int i) {
        if (this.ˏ.offer(ˏ(str, i == 1 ? 3500 : 2000))) {
            this.ˋ.sendEmptyMessage(1);
        }
    }

    protected a ˏ(String str, int i) {
        int dimensionPixelSize;
        View inflate = LayoutInflater.from(this.ˊ).inflate(b.ˏ, null);
        TextView textView = (TextView) inflate.findViewById(d.ˋ);
        textView.setText(str);
        int i2 = 2005;
        if (VERSION.SDK_INT >= 26) {
            i2 = 2038;
        }
        LayoutParams layoutParams = new LayoutParams(-2, -2, i2, 280, -2);
        if (this.ˊ.getResources().getConfiguration().orientation == 1) {
            layoutParams.gravity = 80;
            layoutParams.y = this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ˎ);
            dimensionPixelSize = this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ॱ) - this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ˋ);
        } else {
            layoutParams.gravity = 80;
            layoutParams.x = -(azb.ॱ(this.ˊ) / 4);
            layoutParams.y = this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ˎ);
            dimensionPixelSize = ((azb.ॱ(this.ˊ) / 2) - this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ˊ)) - this.ˊ.getResources().getDimensionPixelSize(o.bkw.a.ˋ);
        }
        textView.setMaxWidth(dimensionPixelSize);
        textView.setText(str);
        a aVar = new a();
        aVar.ˎ(layoutParams);
        aVar.ˊ((long) i);
        aVar.ॱ(inflate);
        return aVar;
    }
}
